package com.explorati.LeetCode167.twosum2;

/**
 * 方法一：暴力解法 双重循环 167. Two Sum II - Input array is sorted
 * 
 * Input: numbers = [2,7,11,15], target = 9 Output: [1,2] Explanation: The sum
 * of 2 and 7 is 9. Therefore index1 = 1, index2 = 2.
 * 
 * @author explorati
 *
 */
public class Solution {
	public static int[] twoSum(int[] numbers, int target) {
		int[] res = new int[2];
		for (int i = 0; i < numbers.length; i++) {
			for (int j = 0; j < numbers.length; j++) {
				if (numbers[i] + numbers[j] == target) {
					// 去除相等索引
					if (i == j) {
						break;
					}
					res[0] = i;
					res[1] = j;
					return res;
				}
			}
		}
		return res;
	}

	public static void main(String[] args) {
		int[] numbers = { 2, 7, 9, 22 };
		int[] arr = twoSum(numbers, 9);
		for (int i : arr) {
			System.out.print(i + "  ");
		}
	}
}
